﻿Public Class Main

    Dim TechTree() As String = {"Light", "Medium", "Heavy", "TD", "SPG"}
    Dim ChinaLight() As String = {"Renault NC-31", "Vickers Mk. E Type B", "Type 2597 Chi-Ha", "M5A1 Stuart", "59-16", "Type 62", "WZ-131", "WZ-132"}
    Dim ChinaMedium() As String = {"Type T-34", "Type 58", "T-34-1", "T-34-2", "Type 59", "Type 59 G", "WZ-120", "121"}
    Dim ChinaHeavy() As String = {"IS-2", "110", "WZ-111", "WZ-111 model 1-4", "113"}
    Dim FranceLight() As String = {"RenaultFT", "D1", "Hotchkiss H35", "AMX 38", "AMX 40", "ELC AMX", "AMX 12t", "AMX 13 75", "AMX 13 90"}
    Dim FranceMedium() As String = {"D2", "Lorraine 40 t", "Bat Chatillon 25 t"}
    Dim FranceHeavy() As String = {"B1", "BDR G1B", "ARL 44", "AMX M4(1945)", "AMX 50 100", "FCM 50 t", "AMX 50 120", "AMX 50B"}
    Dim FranceTD() As String = {"RenaultFT AC", "FCM 36 PaK40", "Renault UE 57", "Somua SAu-40", "S-35 CA", "ARL V39", "AMX AC Mle. 1946", "AMX AC Mle. 1948", "AMX 50 Foch", "AMX-50 Foch (155)"}
    Dim FranceSPG() As String = {"RenaultBS", "Lorraine39 L AM", "105 leFH18B2", "AMX 105AM", "AMX 13 F3 AM", "Lorraine155 50", "Lorraine155 51", "Bat Chatillon 155"}
    Dim GermanyLight() As String = {"Leichttraktor", "PzKpfw 35 (t)", "PzKpfw 28H735 (f)", "PzKpfw II", "PzKpfw 38 (t)", "PzKpfw II Ausf. J", "PzKpfw II Luchs", "PzKpfw III Ausf. A", "T-15", "PzKpfw 38 nA", "VK 1602 Leopard", "VK 2801"}
    Dim GermanyMedium() As String = {"PzKpfw S35 739 (f)", "PzKpfw III", "PzKpfw III/IV", "PzKpfw IV", "PzKpfw IV Hydraulic", "T-25", "PzKpfw IV Schmalturm", "PzKpfw V-IV", "PzKpfw V-IV Alpha", "VK 3001 (H)", "VK 3001 (P)", "VK 3601 (H)", "Panther PzV/M10", "PzKpfw V Panther", "VK 3002 (DB)", "Panther II", "E-50", "E-50 Ausf. M"}
    Dim GermanyHeavy() As String = {"PzKpfw B2 740 (f)", "PzKpfw VI Tiger", "PzKpfw VI Tiger (P)", "Lowe", "PzKpfw VIB Tiger II", "VK 4502 (P) Ausf. A", "E-75", "VK 4502 (P) Ausf. B", "E-100", "Maus"}
    Dim GermanyTD() As String = {"Panzerjager I", "Marder II", "Hetzer", "StuG III", "Dicker Max", "JagdPz IV", "Jagdpanther", "8.8 cm PaK 43 Jagdtiger", "Ferdinand", "Jagdpanther II", "Jagdtiger", "JagdPz E-100"}
    Dim GermanySPG() As String = {"Sturmpanzer I Bison", "Sturmpanzer II", "Wespe", "Grille", "Hummel", "GW Panther", "GW Tiger", "GW Typ E"}
    Dim UKLight() As String = {"Cruiser Mk. I", "Cruiser Mk. III", "Cruiser Mk. II", "Cruiser Mk. IV", "Covenanter", "Valentine", "Crusader"}
    Dim UKMedium() As String = {"Medium Mk. I", "Medium Mk. II", "Medium Mk. III", "Matilda", "Matilda Black Prince", "Cromwell", "Comet", "Centurion Mk. I", "Centurion Mk. 7/1", "FV4202"}
    Dim UKHeavy() As String = {"Churchill I", "Churchill VII", "TOG II", "Black Prince", "Caernarvon", "Conqueror", "FV215b"}
    Dim UKTD() As String = {"AT-15A"}
    Dim USALight() As String = {"T1 Cunningham", "M2 LT", "T1E6", "T2 LT", "M22 Locust", "M3 Stuart", "MTLS-1G14", "M5 Stuart", "M24 Chaffee", "T21", "T71"}
    Dim USAMedium() As String = {"T2 MT", "M2 MT", "M3 Lee", "M4 Sherman", "M4A2E4", "M7 MT", "Ram-II", "M4A3E2", "M4A3E8", "T20", "M26 Pershing", "T26E4 Super Pershing", "T69", "M46 Patton", "T54E1", "M48A1"}
    Dim USAHeavy() As String = {"T1 HT", "T14", "M6", "T29", "M6A2E1", "T32", "T34", "M103", "T110E5", "T57 HT"}
    Dim USATD() As String = {"T18", "T82", "M8A1", "T40", "M10 Wolverine", "T49", "M18 Hellcat", "M36 Jackson", "T25 AT", "T25/2", "T28", "T28 Prototype", "T30", "T95", "T110E3", "T110E4"}
    Dim USASPG() As String = {"T57", "M37", "M7 Priest", "M41", "M12", "M40/M43", "T92"}
    Dim USSRLight() As String = {"MS-1", "BT-2", "Tetrarch", "T-26", "BT-7", "BT-SV", "M3 Stuart Lend Lease", "T-127", "T-46", "A-20", "T-50", "VAlentine II", "T-50-2"}
    Dim USSRMedium() As String = {"A-32", "T-28", "Matilda IV", "T-34", "T-34-85", "KV-13", "T-43", "T-44", "T-54", "T-62A"}
    Dim USSRHeavy() As String = {"Churchill III", "KV-1", "KV-220", "KV-220 Beta-Test", "KV-1S", "KV-2", "T-150", "IS", "KV-3", "IS-3", "IS-6", "KV-4", "KV-5", "IS-8", "ST-I", "IS-4", "IS-7"}
    Dim USSRTD() As String = {"AT-1", "SU-76", "SU-85B", "SU-85", "SU-85I", "SU-100", "SU-100M1", "SU-122-44", "SU-152", "ISU-152", "SU-101", "Object 704", "SU-122-54", "Object 263", "Object 268"}
    Dim USSRSPG() As String = {"SU-18", "SU-26", "SU-5", "SU-8", "S-51", "SU-14", "Object 212", "Object 261"}
    Dim path As String = "Changelog.txt"
    Dim x As Integer
    Public displayMatches As New MatchMaker

    Private Sub cboxCountry_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboxCountry.SelectedIndexChanged
        cboxTankType.Items.Clear()
        Select Case cboxCountry.SelectedItem
            Case "China"
                cboxTankType.Items.AddRange(TechTree)
                cboxTankType.Items.Remove("TD")
                cboxTankType.Items.Remove("SPG")
                cboxTank.Items.AddRange(ChinaLight)
                cboxTankType.SelectedIndex = 0
            Case "France"
                cboxTankType.Items.AddRange(TechTree)
                cboxTank.Items.AddRange(FranceLight)
                cboxTankType.SelectedIndex = 0
            Case "Germany"
                cboxTankType.Items.AddRange(TechTree)
                cboxTank.Items.AddRange(GermanyLight)
                cboxTankType.SelectedIndex = 0
            Case "U.K."
                cboxTankType.Items.AddRange(TechTree)
                cboxTankType.Items.Remove("SPG")
                cboxTank.Items.AddRange(UKLight)
                cboxTankType.SelectedIndex = 0
            Case "U.S.A."
                cboxTankType.Items.AddRange(TechTree)
                cboxTank.Items.AddRange(USALight)
                cboxTankType.SelectedIndex = 0
            Case "U.S.S.R."
                cboxTankType.Items.AddRange(TechTree)
                cboxTank.Items.AddRange(USSRLight)
                cboxTankType.SelectedIndex = 0
        End Select
    End Sub

    Private Sub cboxTankType_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboxTankType.SelectedIndexChanged
        cboxTank.Items.Clear()
        Select Case cboxCountry.SelectedItem
            Case "China"
                Select Case cboxTankType.SelectedItem
                    Case "Light"
                        cboxTank.Items.AddRange(ChinaLight)
                        cboxTank.SelectedIndex = 0
                    Case "Medium"
                        cboxTank.Items.AddRange(ChinaMedium)
                        cboxTank.SelectedIndex = 0
                    Case "Heavy"
                        cboxTank.Items.AddRange(ChinaHeavy)
                        cboxTank.SelectedIndex = 0
                End Select
            Case "France"
                Select Case cboxTankType.SelectedItem
                    Case "Light"
                        cboxTank.Items.AddRange(FranceLight)
                        cboxTank.SelectedIndex = 0
                    Case "Medium"
                        cboxTank.Items.AddRange(FranceMedium)
                        cboxTank.SelectedIndex = 0
                    Case "Heavy"
                        cboxTank.Items.AddRange(FranceHeavy)
                        cboxTank.SelectedIndex = 0
                    Case "TD"
                        cboxTank.Items.AddRange(FranceTD)
                        cboxTank.SelectedIndex = 0
                    Case "SPG"
                        cboxTank.Items.AddRange(FranceSPG)
                        cboxTank.SelectedIndex = 0
                End Select
            Case "Germany"
                Select Case cboxTankType.SelectedItem
                    Case "Light"
                        cboxTank.Items.AddRange(GermanyLight)
                        cboxTank.SelectedIndex = 0
                    Case "Medium"
                        cboxTank.Items.AddRange(GermanyMedium)
                        cboxTank.SelectedIndex = 0
                    Case "Heavy"
                        cboxTank.Items.AddRange(GermanyHeavy)
                        cboxTank.SelectedIndex = 0
                    Case "TD"
                        cboxTank.Items.AddRange(GermanyTD)
                        cboxTank.SelectedIndex = 0
                    Case "SPG"
                        cboxTank.Items.AddRange(GermanySPG)
                        cboxTank.SelectedIndex = 0
                End Select
            Case "U.K."
                Select Case cboxTankType.SelectedItem
                    Case "Light"
                        cboxTank.Items.AddRange(UKLight)
                        cboxTank.SelectedIndex = 0
                    Case "Medium"
                        cboxTank.Items.AddRange(UKMedium)
                        cboxTank.SelectedIndex = 0
                    Case "Heavy"
                        cboxTank.Items.AddRange(UKHeavy)
                        cboxTank.SelectedIndex = 0
                End Select
            Case "U.S.A."
                Select Case cboxTankType.SelectedItem
                    Case "Light"
                        cboxTank.Items.AddRange(USALight)
                        cboxTank.SelectedIndex = 0
                    Case "Medium"
                        cboxTank.Items.AddRange(USAMedium)
                        cboxTank.SelectedIndex = 0
                    Case "Heavy"
                        cboxTank.Items.AddRange(USAHeavy)
                        cboxTank.SelectedIndex = 0
                    Case "TD"
                        cboxTank.Items.AddRange(USATD)
                        cboxTank.SelectedIndex = 0
                    Case "SPG"
                        cboxTank.Items.AddRange(USASPG)
                        cboxTank.SelectedIndex = 0
                End Select
            Case "U.S.S.R."
                Select Case cboxTankType.SelectedItem
                    Case "Light"
                        cboxTank.Items.AddRange(USSRLight)
                        cboxTank.SelectedIndex = 0
                    Case "Medium"
                        cboxTank.Items.AddRange(USSRMedium)
                        cboxTank.SelectedIndex = 0
                    Case "Heavy"
                        cboxTank.Items.AddRange(USSRHeavy)
                        cboxTank.SelectedIndex = 0
                    Case "TD"
                        cboxTank.Items.AddRange(USSRTD)
                        cboxTank.SelectedIndex = 0
                    Case "SPG"
                        cboxTank.Items.AddRange(USSRSPG)
                        cboxTank.SelectedIndex = 0
                End Select
        End Select
    End Sub

    Private Sub cboxTank_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboxTank.SelectedIndexChanged
        If dgvMatchMaker.ColumnCount = 0 Then
            dgvMatchMaker.Columns.Add("colCountry", "Country")
            dgvMatchMaker.Columns("colCountry").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            dgvMatchMaker.Columns.Add("colType", "Tank Type")
            dgvMatchMaker.Columns("colType").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            dgvMatchMaker.Columns.Add("colTier", "Tier")
            dgvMatchMaker.Columns("colTier").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            dgvMatchMaker.Columns.Add("colTank", "Tank")
            dgvMatchMaker.Columns("colTank").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            dgvMatchMaker.Columns.Add("colBT", "Battle Tier")
            dgvMatchMaker.Columns("colBT").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        End If
        dgvMatchMaker.Rows.Clear()
        Try
            displayMatches.getMatches()
        Catch ex As Exception
            x = 1
        End Try
    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub ProgramGoalsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ProgramGoalsToolStripMenuItem.Click
        ProgramGoals.Show()
    End Sub

    Private Sub ChangeLogToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ChangeLogToolStripMenuItem.Click
        Try
            For Each line As String In System.IO.File.ReadAllLines(path)
                If V10ToolStripMenuItem.Text > line.Trim(V10ToolStripMenuItem.Text) Then ChangelogWriter()
            Next
            Process.Start("Changelog.txt")
        Catch ex As Exception
            ChangelogWriter()
            Process.Start("Changelog.txt")
        End Try
    End Sub

    Private Sub WoTWikiToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles WoTWikiToolStripMenuItem.Click
        Process.Start("http://wiki.worldoftanks.com/Main_Page")
    End Sub

    Private Sub CheckForUpdateToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CheckForUpdateToolStripMenuItem.Click
        Process.Start("http://code.google.com/p/wot-match-maker/downloads/list")
    End Sub

    Private Sub OpenSourceToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenSourceToolStripMenuItem.Click
        Process.Start("http://code.google.com/p/wot-match-maker/source/checkout")
    End Sub

    Private Sub lblLink_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblLink.LinkClicked
        Process.Start("http://wiki.worldoftanks.com/Battle_Mechanics#Matchmaking")
    End Sub

    Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If System.IO.File.Exists(path) = False Then
            ChangelogWriter()
        ElseIf System.IO.File.Exists(path) = True Then
            For Each line As String In System.IO.File.ReadAllLines(path)
                If V10ToolStripMenuItem.Text > line.Trim(V10ToolStripMenuItem.Text) Then ChangelogWriter()
            Next
        End If

        If x <> 0 Then displayMatches.getMatches()
    End Sub

    Private Sub ChangelogWriter()
        Dim changelog As String = "v3.3" & vbCrLf & "     - Added 'Country', 'Tank Type', and 'Tank Tier' columns." & vbCrLf & "     - Table will now sort tanks by Country by default." & vbCrLf & "     - Removed 'Premium' tank type." & vbCrLf & "v3.2" & vbCrLf & "     - Updated to match WoT v8.3." & vbCrLf & "     - Changed some tank names to match those found on WoT Wiki." & vbCrLf & "     - Code cleanup." & vbCrLf & "v3.1.1" & vbCrLf & "     - Added new T1E6 U.S. Premium" & vbCrLf & "v3.1" & vbCrLf & "     - Fixed some tank names not matching those in game." & vbCrLf & "     - Cleaned up code for creating the changelog file." & vbCrLf & "v3.0" & vbCrLf & "     - Updated to match WoT v8.2." & vbCrLf & "     - Substituted changelog for a simple text file." & vbCrLf & "v2.2" & vbCrLf & "     - Code cleanup." & vbCrLf & "     - Fixed some typos with multiple tanks." & vbCrLf & "v2.1" & vbCrLf & "     - Program completely recoded so that all possible matches are displayed." & vbCrLf & "v2.0" & vbCrLf & "     - Changed list to table that displays both the tank and its battle tiers." & vbCrLf & "     - Added a link to the WoT Wiki's Battle Mechanics page." & vbCrLf & "     - Fixed PzKpfw V-IV not being included in the list of tanks." & vbCrLf & "     - Fixed Several misspellings of various tanks." & vbCrLf & "v1.0" & vbCrLf & "     - Initial Release"
        Dim writer As New System.IO.StreamWriter(path, False)
        writer.Write(changelog)
        writer.Close()
    End Sub

End Class
